package cn.edu.neusoft.wuguangsheng.flowerimpression.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.CommentGoodsActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.ShopInfoActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.OrderBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.service.Service;

public class OrderAdapter extends BaseAdapter<OrderBean> {

    public OrderAdapter(Context context, List<OrderBean> items, int layoutResource){
        super(context, items, layoutResource);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView= LayoutInflater.from(context).inflate(layoutResourse,parent,false);
        OrderViewHolder orderViewHolder = new OrderViewHolder(itemView);
        return orderViewHolder;
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        OrderViewHolder orderViewHolder=(OrderViewHolder) holder;
        OrderBean orderBean=items.get(position);

        final String shopname = orderBean.getShop_name();
        final String goodname = orderBean.getGood_name();
        final String goodprice = orderBean.getOg_goodprice();
        final String num = orderBean.getOg_goodnum();
        final String allprice = orderBean.getOg_goodallprice();
        final String goodphoto = Service.BASE_URL+"flower_impression/public/uploads/"+orderBean.getGood_photo();
        final String shopid = orderBean.getShop_id();
        final String order_id = orderBean.getOrder_id();

        orderViewHolder.orderitem_shopname.setText(shopname+"---->");
        orderViewHolder.orderitem_goodsname.setText(goodname);
        orderViewHolder.orderitem_goodsprice.setText("￥"+goodprice);
        orderViewHolder.orderitem_buynum.setText("X"+num);
        orderViewHolder.orderitem_buyallprice.setText("￥"+allprice);
        Picasso.with(context).load(goodphoto).into(orderViewHolder.orderitem_goodsphoto);

        orderViewHolder.orderitem_shopname.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context,ShopInfoActivity.class);
                intent.putExtra("shopid",shopid);
                context.startActivity(intent);
            }
        });
        orderViewHolder.orderitem_ljpl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intentl = new Intent(context, CommentGoodsActivity.class);
                intentl.putExtra("order_id",order_id);
                context.startActivity(intentl);
            }
        });


//        final String shopname = shopInfoBean.getShop_name();
//        final String intro = shopInfoBean.getShop_intro();
//        final String shopid = shopInfoBean.getShop_id();
//        final String img = Service.BASE_URL+"flower_impression/public/uploads/"+shopInfoBean.getShop_photo();
//
//        viewHolder.shopitem_name.setText(shopname);
//        viewHolder.shopitem_intro.setText(intro);
//        viewHolder.shopitem_star.setNumStars(4);
//
//        Picasso.with(context).load(img).into(viewHolder.shopitem_img);
//
//        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent = new Intent(context, ShopInfoActivity.class);
//                intent.putExtra("shopid",shopid);
//                context.startActivity(intent);
//            }
//        });
    }
}
